package com.khyr.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.khyr.Vo.LogVo;
import com.khyr.dao.PurchaseInVentoryLog;
import com.khyr.entity.StockInventoryLog;
import com.khyr.service.PurChaseInVentoryLogService;
import com.khyr.vo.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @className: PlogServiceImpl
 * @author: Zyl
 * @date: 2025/3/14 18:03
 * @Version: 1.0
 * @description:
 */
@Service
public class PlogServiceImpl implements PurChaseInVentoryLogService {
    @Autowired
    private PurchaseInVentoryLog purchaseInVentoryLog;
    @Override
    public R<Page<StockInventoryLog>> find(LogVo data) {
        QueryWrapper<StockInventoryLog> queryWrapper = new QueryWrapper<>();
        if (data.getPurchaseId() != null){
            queryWrapper.eq("purchase_id",data.getPurchaseId());
        }
        if(data.getMedicinesName()!=null){
            queryWrapper.like("medicines_name",data.getMedicinesName());
        }
        if(data.getMedicinesType()!=null){
            queryWrapper.like("medicines_type",data.getMedicinesType());
        }
       if(data.getPrescriptionType()!=null){
           queryWrapper.like("prescription_type",data.getPrescriptionType());
       }
       if(data.getProducterId()!=null){
           queryWrapper.like("producter_id",data.getProducterId());
       }
       if(data.getDateRange()!=null && data.getDateRange().length==2){
           queryWrapper.between("create_time",data.getDateRange()[0],data.getDateRange()[1]);
       }
       Page<StockInventoryLog> page = new Page<>(data.getPageNum(),data.getPageSize());
       Page<StockInventoryLog> page1 = purchaseInVentoryLog.selectPage(page, queryWrapper);
       return new R<>(200,"获取成功",page1);
    }
}
